﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;

using System.Web.Services;

using System.IO.MemoryMappedFiles;
public partial class realia_Details : System.Web.UI.Page
{
    string agent;
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Text = Request["imgid"].ToString();
        SqlConnection conf = null;
        conf = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conf.Open();
        SqlCommand hmdf = new SqlCommand("select * from properties where p_id='" + Request["imgid"].ToString() + "'", conf);
        Session["imgid"] = Request["imgid"].ToString();

        SqlDataReader hrf = hmdf.ExecuteReader();
        // Response.Write(@"<script language='javascript'>alert('loop 1')</script>");

        while (hrf.Read())
        {
            string str = hrf[2].ToString();
            str = Session["imgid"].ToString();
            Image1.ImageUrl = "DetailsImage.ashx?imgid=" + str.ToString();
            Label17.Text = hrf[12].ToString();
            Label16.Text = hrf[118].ToString();
            Label15.Text = hrf[59].ToString();
            Label14.Text = hrf[52].ToString();
            Label13.Text = hrf[1].ToString();
            Label35.Text = hrf[34].ToString();
            Label12.Text = hrf[57].ToString();
            Label11.Text = hrf[21].ToString();
            Label10.Text = hrf[15].ToString();
           
            Label36.Text = hrf[47].ToString();
            Label9.Text = hrf[1].ToString();
            Label3.Text = hrf[15].ToString();
            Label4.Text = hrf[43].ToString();
            Label5.Text = hrf[66].ToString();
            Label6.Text = hrf[67].ToString();
            Label7.Text = hrf[12].ToString();
            Label8.Text = hrf[56].ToString();
            //Label1.Text = hrf[9].ToString();
            Label2.Text = hrf[15].ToString();




            Image6.ImageUrl = "AgentSecondLast.ashx";
            Image2.ImageUrl = "FirstProperty.ashx";
            Image3.ImageUrl = "SecondLastProperty.ashx";
            Image4.ImageUrl = "ThirdLastProperty.ashx";
            //Image5.ImageUrl = "FourthLastProperty.ashx";
        }
        hrf.Close();
        conf.Close();
        SqlConnection con4 = null;
        con4= new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        con4.Open();
        SqlCommand hmd4= new SqlCommand ("select * from properties where ID=(SELECT MAX(ID) FROM properties)", con4);
        Session["imgid"] = Request["imgid"].ToString();

        SqlDataReader hrf4 = hmd4.ExecuteReader();
        // Response.Write(@"<script language='javascript'>alert('loop 1')</script>");

        while (hrf4.Read())
        {
           
            Label18.Text =hrf4 [15].ToString ();
            Label19.Text =hrf4 [9].ToString ();
            Label20.Text =hrf4 [21].ToString ();
                //Label21.Text =hrf [].ToString ();
            //Label21.Text =hrf [].ToString ();
            //Label4.Text =hrf [].ToString ();
            //    Label6.Text =hrf [].ToString ();
            //Label5.Text =hrf [].ToString ();
            //Label4.Text =hrf [].ToString ();





    }
        hrf4.Close();
        con4.Close();
        SqlConnection con4a = null;
        con4a = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        con4a.Open();
        SqlCommand hmd4a = new SqlCommand("select * from properties where ID=(SELECT MAX(ID)-1 FROM properties)", con4a);
        Session["imgid"] = Request["imgid"].ToString();

        SqlDataReader hrf4a = hmd4a.ExecuteReader();
        // Response.Write(@"<script language='javascript'>alert('loop 1')</script>");

        while (hrf4a.Read())
        {

            Label21.Text = hrf4a[15].ToString();
            Label22.Text = hrf4a[9].ToString();
            Label23.Text = hrf4a[21].ToString();
            //Label21.Text =hrf [].ToString ();
            //Label21.Text =hrf [].ToString ();
            //Label4.Text =hrf [].ToString ();
            //    Label6.Text =hrf [].ToString ();
            //Label5.Text =hrf [].ToString ();
            //Label4.Text =hrf [].ToString ();





        }
        hrf4a.Close();
        con4a.Close();
      
         SqlConnection con4aa = null;
        con4aa = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        con4aa.Open();
        SqlCommand hmd4aa = new SqlCommand("select * from properties where ID=(SELECT MAX(ID)-2 FROM properties)", con4aa);
        Session["imgid"] = Request["imgid"].ToString();

        SqlDataReader hrf4aa = hmd4aa.ExecuteReader();
        // Response.Write(@"<script language='javascript'>alert('loop 1')</script>");

        while (hrf4aa.Read())
        {

            Label24.Text = hrf4aa[15].ToString();
            Label25.Text = hrf4aa[9].ToString();
            Label26.Text = hrf4aa[21].ToString();
            //Label21.Text =hrf [].ToString ();
            //Label21.Text =hrf [].ToString ();
            //Label4.Text =hrf [].ToString ();
            //    Label6.Text =hrf [].ToString ();
            //Label5.Text =hrf [].ToString ();
            //Label4.Text =hrf [].ToString ();

        }
        hrf4aa.Close();
        con4aa.Close();
        
         SqlConnection con4ad = null;
        con4ad = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        con4ad.Open();
        SqlCommand hmd4ad = new SqlCommand("select * from properties where ID=(SELECT MAX(ID)-3 FROM properties)", con4ad);
        Session["imgid"] = Request["imgid"].ToString();

        SqlDataReader hrf4ad = hmd4ad.ExecuteReader();
        // Response.Write(@"<script language='javascript'>alert('loop 1')</script>");

        while (hrf4ad.Read())
        {

            //Label27.Text = hrf4ad[9].ToString();
            //Label28.Text = hrf4ad[10].ToString();
            //Label29.Text = hrf4ad[11].ToString();
            //Label21.Text =hrf [].ToString ();
            //Label21.Text =hrf [].ToString ();
            //Label4.Text =hrf [].ToString ();
            //    Label6.Text =hrf [].ToString ();
            //Label5.Text =hrf [].ToString ();
            //Label4.Text =hrf [].ToString ();

        }
        hrf4ad.Close();
        con4ad.Close();

        SqlConnection con4aa4 = null;
        con4aa4 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        con4aa4.Open();
        SqlCommand hmd4aa4 = new SqlCommand("select * from agent_add where ID=(SELECT MAX(ID)-1 FROM agent_add)  ", con4aa4);
        Session["imgid"] = Request["imgid"].ToString();

        SqlDataReader hrf4aa4 = hmd4aa4.ExecuteReader();
        // Response.Write(@"<script language='javascript'>alert('loop 1')</script>");

        while (hrf4aa4.Read())
        {

            Label30.Text = hrf4aa4[2].ToString();
            Label31.Text = hrf4aa4[8].ToString();
            Label32.Text = hrf4aa4[15].ToString();
            Label33.Text = hrf4aa4[9].ToString();
            Label34.Text = hrf4aa4[13].ToString();
            //Label21.Text =hrf [].ToString ();
            //Label21.Text =hrf [].ToString ();
            //Label4.Text =hrf [].ToString ();
            //    Label6.Text =hrf [].ToString ();
            //Label5.Text =hrf [].ToString ();
            //Label4.Text =hrf [].ToString ();

        }



        hrf4aa4.Close();
        con4aa4.Close();


       
    }
  
    protected void Button1_Click1(object sender, EventArgs e)
    {
     
            SqlConnection conn = null;

            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
            conn.Open();
            SqlCommand cmd = new SqlCommand("Insert into message1 values(@p_id,@email,@ph_no,@address,@message,@date_,@status_ )", conn);
            cmd.Parameters.AddWithValue("@p_id", Session["imgid"]);
            cmd.Parameters.AddWithValue("@email", txtemail.Text); 
            cmd.Parameters.AddWithValue("@ph_no", txtphno.Text);
            cmd.Parameters.AddWithValue("@address", txtadd.Text);
            cmd.Parameters.AddWithValue("@message", txtmessage.Text);
            cmd.Parameters.AddWithValue("@date_", System.DateTime.Now);
            cmd.Parameters.AddWithValue("@status_", "0");
            cmd.ExecuteNonQuery();
            conn.Close();
            Response.Redirect("feedback.aspx");

        }
    }
